<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::PKey::EC - openssl: Ruby Standard Library Documentation</title>


<script src="../../js/navigation.js" defer></script>
<script src="../../js/search.js" defer></script>
<script src="../../js/search_index.js" defer></script>
<script src="../../js/searcher.js" defer></script>
<script src="../../js/darkfish.js" defer></script>

<script src="../../js/jquery-3.2.0.min.js"></script>

<script src="../../js/vue.min.js"></script>
<script src="../../js/js.cookie.min.js"></script>

<link href="../../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../../css/rdoc.css" rel="stylesheet">
<link href="../../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../";
  var index_rel_prefix = "../../";
  var darkModeCsseHref = "../../css/rdoc-dm.css"
  var defaultModeCssHref = "../../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../../table_of_contents.html#pages">Pages</a>
    <a href="../../table_of_contents.html#classes">Classes</a>
    <a href="../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="PKey.html">OpenSSL::PKey::PKey</a>
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="../Marshal.html">OpenSSL::Marshal</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-builtin_curves">::builtin_curves</a>
    <li ><a href="#method-c-generate">::generate</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-check_key">#check_key</a>
    <li ><a href="#method-i-dh_compute_key">#dh_compute_key</a>
    <li ><a href="#method-i-dsa_sign_asn1">#dsa_sign_asn1</a>
    <li ><a href="#method-i-dsa_verify_asn1">#dsa_verify_asn1</a>
    <li ><a href="#method-i-export">#export</a>
    <li ><a href="#method-i-generate_key">#generate_key</a>
    <li ><a href="#method-i-generate_key-21">#generate_key!</a>
    <li ><a href="#method-i-group">#group</a>
    <li ><a href="#method-i-group-3D">#group=</a>
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-private-3F">#private?</a>
    <li ><a href="#method-i-private_key">#private_key</a>
    <li ><a href="#method-i-private_key-3D">#private_key=</a>
    <li ><a href="#method-i-private_key-3F">#private_key?</a>
    <li ><a href="#method-i-public-3F">#public?</a>
    <li ><a href="#method-i-public_key">#public_key</a>
    <li ><a href="#method-i-public_key-3D">#public_key=</a>
    <li ><a href="#method-i-public_key-3F">#public_key?</a>
    <li ><a href="#method-i-to_der">#to_der</a>
    <li ><a href="#method-i-to_pem">#to_pem</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-OpenSSL::PKey::EC">
    <h1 id="class-OpenSSL::PKey::EC" class="class">
      class OpenSSL::PKey::EC
    </h1>

    <section class="description">
    
<p><a href="EC.html"><code>OpenSSL::PKey::EC</code></a> provides access to Elliptic Curve Digital Signature Algorithm (ECDSA) and Elliptic Curve Diffie-Hellman (ECDH).</p>

<h3 id="class-OpenSSL::PKey::EC-label-Key+exchange">Key exchange<span><a href="#class-OpenSSL::PKey::EC-label-Key+exchange">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">ec1</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">EC</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-string">&quot;prime256v1&quot;</span>)
<span class="ruby-identifier">ec2</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">EC</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-string">&quot;prime256v1&quot;</span>)
<span class="ruby-comment"># ec1 and ec2 have own private key respectively</span>
<span class="ruby-identifier">shared_key1</span> = <span class="ruby-identifier">ec1</span>.<span class="ruby-identifier">dh_compute_key</span>(<span class="ruby-identifier">ec2</span>.<span class="ruby-identifier">public_key</span>)
<span class="ruby-identifier">shared_key2</span> = <span class="ruby-identifier">ec2</span>.<span class="ruby-identifier">dh_compute_key</span>(<span class="ruby-identifier">ec1</span>.<span class="ruby-identifier">public_key</span>)

<span class="ruby-identifier">p</span> <span class="ruby-identifier">shared_key1</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">shared_key2</span> <span class="ruby-comment">#=&gt; true</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="EXPLICIT_CURVE">EXPLICIT_CURVE
          <dd>
          <dt id="NAMED_CURVE">NAMED_CURVE
          <dd>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-builtin_curves" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          builtin_curves &rarr; [[sn, comment], ...]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Obtains a list of all predefined curves by the <a href="../../OpenSSL.html"><code>OpenSSL</code></a>. Curve names are returned as sn.</p>

<p>See the <a href="../../OpenSSL.html"><code>OpenSSL</code></a> documentation for EC_get_builtin_curves().</p>

                              <div class="method-source-code" id="builtin_curves-source">
            <pre>static VALUE ossl_s_builtin_curves(VALUE self)
{
    EC_builtin_curve *curves = NULL;
    int n;
    int crv_len = rb_long2int(EC_get_builtin_curves(NULL, 0));
    VALUE ary, ret;

    curves = ALLOCA_N(EC_builtin_curve, crv_len);
    if (curves == NULL)
        return Qnil;
    if (!EC_get_builtin_curves(curves, crv_len))
        ossl_raise(rb_eRuntimeError, &quot;EC_get_builtin_curves&quot;);

    ret = rb_ary_new2(crv_len);

    for (n = 0; n &lt; crv_len; n++) {
        const char *sname = OBJ_nid2sn(curves[n].nid);
        const char *comment = curves[n].comment;

        ary = rb_ary_new2(2);
        rb_ary_push(ary, rb_str_new2(sname));
        rb_ary_push(ary, comment ? rb_str_new2(comment) : Qnil);
        rb_ary_push(ret, ary);
    }

    return ret;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-generate" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          generate(ec_group) &rarr; ec
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          generate(string) &rarr; ec
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new <a href="EC.html"><code>EC</code></a> instance with a new random private and public key.</p>

                              <div class="method-source-code" id="generate-source">
            <pre>static VALUE
ossl_ec_key_s_generate(VALUE klass, VALUE arg)
{
    EVP_PKEY *pkey;
    EC_KEY *ec;
    VALUE obj;

    obj = rb_obj_alloc(klass);

    ec = ec_key_new_from_group(arg);
    pkey = EVP_PKEY_new();
    if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec) != 1) {
        EVP_PKEY_free(pkey);
        EC_KEY_free(ec);
        ossl_raise(eECError, &quot;EVP_PKEY_assign_EC_KEY&quot;);
    }
    RTYPEDDATA_DATA(obj) = pkey;

    if (!EC_KEY_generate_key(ec))
        ossl_raise(eECError, &quot;EC_KEY_generate_key&quot;);

    return obj;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::PKey::EC.new
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::PKey::EC.new(ec_key)
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::PKey::EC.new(ec_group)
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::PKey::EC.new(&quot;secp112r1&quot;)
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::PKey::EC.new(pem_string [, pwd])
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::PKey::EC.new(der_string)
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new <a href="EC.html"><code>EC</code></a> object from given arguments.</p>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
{
    EVP_PKEY *pkey;
    EC_KEY *ec;
    BIO *in;
    VALUE arg, pass;
    int type;

    TypedData_Get_Struct(self, EVP_PKEY, &amp;ossl_evp_pkey_type, pkey);
    if (pkey)
        rb_raise(rb_eTypeError, &quot;pkey already initialized&quot;);

    rb_scan_args(argc, argv, &quot;02&quot;, &amp;arg, &amp;pass);
    if (NIL_P(arg)) {
        if (!(ec = EC_KEY_new()))
            ossl_raise(eECError, &quot;EC_KEY_new&quot;);
        goto legacy;
    }
    else if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
        ec = ec_key_new_from_group(arg);
        goto legacy;
    }

    pass = ossl_pem_passwd_value(pass);
    arg = ossl_to_der_if_possible(arg);
    in = ossl_obj2bio(&amp;arg);

    pkey = ossl_pkey_read_generic(in, pass);
    BIO_free(in);
    if (!pkey) {
        ossl_clear_error();
        ec = ec_key_new_from_group(arg);
        goto legacy;
    }

    type = EVP_PKEY_base_id(pkey);
    if (type != EVP_PKEY_EC) {
        EVP_PKEY_free(pkey);
        rb_raise(eDSAError, &quot;incorrect pkey type: %s&quot;, OBJ_nid2sn(type));
    }
    RTYPEDDATA_DATA(self) = pkey;
    return self;

  legacy:
    pkey = EVP_PKEY_new();
    if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec) != 1) {
        EVP_PKEY_free(pkey);
        EC_KEY_free(ec);
        ossl_raise(eECError, &quot;EVP_PKEY_assign_EC_KEY&quot;);
    }
    RTYPEDDATA_DATA(self) = pkey;
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-check_key" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          check_key   &rarr; true
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Raises an exception if the key is invalid.</p>

<p>See also the man page EVP_PKEY_public_check(3).</p>

                              <div class="method-source-code" id="check_key-source">
            <pre>static VALUE ossl_ec_key_check_key(VALUE self)
{
#ifdef HAVE_EVP_PKEY_CHECK
    EVP_PKEY *pkey;
    EVP_PKEY_CTX *pctx;
    const EC_KEY *ec;

    GetPKey(self, pkey);
    GetEC(self, ec);
    pctx = EVP_PKEY_CTX_new(pkey, /* engine */NULL);
    if (!pctx)
        ossl_raise(eECError, &quot;EVP_PKEY_CTX_new&quot;);

    if (EC_KEY_get0_private_key(ec) != NULL) {
        if (EVP_PKEY_check(pctx) != 1) {
            EVP_PKEY_CTX_free(pctx);
            ossl_raise(eECError, &quot;EVP_PKEY_check&quot;);
        }
    }
    else {
        if (EVP_PKEY_public_check(pctx) != 1) {
            EVP_PKEY_CTX_free(pctx);
            ossl_raise(eECError, &quot;EVP_PKEY_public_check&quot;);
        }
    }

    EVP_PKEY_CTX_free(pctx);
#else
    EC_KEY *ec;

    GetEC(self, ec);
    if (EC_KEY_check_key(ec) != 1)
        ossl_raise(eECError, &quot;EC_KEY_check_key&quot;);
#endif

    return Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dh_compute_key" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dh_compute_key(pubkey) &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Derives a shared secret by ECDH. <em>pubkey</em> must be an instance of <a href="EC/Point.html"><code>OpenSSL::PKey::EC::Point</code></a> and must belong to the same group.</p>

<p>This method is provided for backwards compatibility, and calls <a href="PKey.html#method-i-derive"><code>derive</code></a> internally.</p>

                              <div class="method-source-code" id="dh_compute_key-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 284</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dh_compute_key</span>(<span class="ruby-identifier">pubkey</span>)
  <span class="ruby-identifier">obj</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">ASN1</span>.<span class="ruby-constant">Sequence</span>([
    <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">ASN1</span>.<span class="ruby-constant">Sequence</span>([
      <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">ASN1</span>.<span class="ruby-constant">ObjectId</span>(<span class="ruby-string">&quot;id-ecPublicKey&quot;</span>),
      <span class="ruby-identifier">group</span>.<span class="ruby-identifier">to_der</span>,
    ]),
    <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">ASN1</span>.<span class="ruby-constant">BitString</span>(<span class="ruby-identifier">pubkey</span>.<span class="ruby-identifier">to_octet_string</span>(<span class="ruby-value">:uncompressed</span>)),
  ])
  <span class="ruby-identifier">derive</span>(<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">to_der</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dsa_sign_asn1" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dsa_sign_asn1(data) &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><strong>Deprecated in version 3.0</strong>. Consider using <a href="PKey.html#method-i-sign_raw"><code>PKey::PKey#sign_raw</code></a> and <a href="PKey.html#method-i-verify_raw"><code>PKey::PKey#verify_raw</code></a> instead.</p>

                              <div class="method-source-code" id="dsa_sign_asn1-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 259</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dsa_sign_asn1</span>(<span class="ruby-identifier">data</span>)
  <span class="ruby-identifier">sign_raw</span>(<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">PKeyError</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">ECError</span>, <span class="ruby-identifier">$!</span>.<span class="ruby-identifier">message</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dsa_verify_asn1" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dsa_verify_asn1(data, sig) &rarr; true | false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><strong>Deprecated in version 3.0</strong>. Consider using <a href="PKey.html#method-i-sign_raw"><code>PKey::PKey#sign_raw</code></a> and <a href="PKey.html#method-i-verify_raw"><code>PKey::PKey#verify_raw</code></a> instead.</p>

                              <div class="method-source-code" id="dsa_verify_asn1-source">
            <pre><span class="ruby-comment"># File openssl/lib/openssl/pkey.rb, line 270</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dsa_verify_asn1</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">sig</span>)
  <span class="ruby-identifier">verify_raw</span>(<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">sig</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">PKeyError</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">ECError</span>, <span class="ruby-identifier">$!</span>.<span class="ruby-identifier">message</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-export" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          export([cipher, password]) &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Serializes a private or public key to a PEM-encoding.</p>
<dl class="rdoc-list label-list"><dt>When the key contains public components only
<dd>
<p>Serializes it into an X.509 SubjectPublicKeyInfo. The parameters <em>cipher</em> and <em>password</em> are ignored.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN PUBLIC KEY-----
[...]
-----END PUBLIC KEY-----</pre>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> instead. This serializes the key into an X.509 SubjectPublicKeyInfo regardless of whether it is a public key or a private key.</p>
</dd><dt>When the key contains private components, and no parameters are given
<dd>
<p>Serializes it into a SEC 1/RFC 5915 ECPrivateKey.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN EC PRIVATE KEY-----
[...]
-----END EC PRIVATE KEY-----</pre>
</dd><dt>When the key contains private components, and <em>cipher</em> and <em>password</em> are given
<dd>
<p>Serializes it into a SEC 1/RFC 5915 ECPrivateKey and encrypts it in OpenSSL’s traditional PEM encryption format. <em>cipher</em> must be a cipher name understood by <a href="../Cipher.html#method-c-new"><code>OpenSSL::Cipher.new</code></a> or an instance of <a href="../Cipher.html"><code>OpenSSL::Cipher</code></a>.</p>

<p>An encrypted PEM-encoded key will look like:</p>

<pre>-----BEGIN EC PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,733F5302505B34701FC41F5C0746E4C0

[...]
-----END EC PRIVATE KEY-----</pre>

<p>Note that this format uses MD5 to derive the encryption key, and hence will not be available on FIPS-compliant systems.</p>
</dd></dl>

<p><strong>This method is kept for compatibility.</strong> This should only be used when the SEC 1/RFC 5915 ECPrivateKey format is required.</p>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> (X.509 SubjectPublicKeyInfo) or <a href="PKey.html#method-i-private_to_pem"><code>private_to_pem</code></a> (PKCS #8 PrivateKeyInfo or EncryptedPrivateKeyInfo) instead.</p>

                              <div class="method-source-code" id="export-source">
            <pre>static VALUE
ossl_ec_key_export(int argc, VALUE *argv, VALUE self)
{
    OSSL_3_const EC_KEY *ec;

    GetEC(self, ec);
    if (EC_KEY_get0_public_key(ec) == NULL)
        ossl_raise(eECError, &quot;can&#39;t export - no public key set&quot;);
    if (EC_KEY_get0_private_key(ec))
        return ossl_pkey_export_traditional(argc, argv, self, 0);
    else
        return ossl_pkey_export_spki(self, 0);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="EC.html#method-i-to_pem">to_pem</a>
                            </div>

                          </div>

                  <div id="method-i-generate_key" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">generate_key</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Generates a new random private and public key.</p>

<p>See also the <a href="../../OpenSSL.html"><code>OpenSSL</code></a> documentation for EC_KEY_generate_key()</p>

<h3 id="method-i-generate_key-label-Example">Example<span><a href="#method-i-generate_key-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">ec</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">EC</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;prime256v1&quot;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">ec</span>.<span class="ruby-identifier">private_key</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">ec</span>.<span class="ruby-identifier">generate_key!</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">ec</span>.<span class="ruby-identifier">private_key</span> <span class="ruby-comment"># =&gt; #&lt;OpenSSL::BN XXXXXX&gt;</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="EC.html#method-i-generate_key-21">generate_key!</a>
                            </div>
                          </div>

                  <div id="method-i-generate_key-21" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">generate_key!</span><span
                                class="method-args">   =&gt; self</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Generates a new random private and public key.</p>

<p>See also the <a href="../../OpenSSL.html"><code>OpenSSL</code></a> documentation for EC_KEY_generate_key()</p>

<h3 id="method-i-generate_key-21-label-Example">Example<span><a href="#method-i-generate_key-21-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">ec</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">EC</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;prime256v1&quot;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">ec</span>.<span class="ruby-identifier">private_key</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">ec</span>.<span class="ruby-identifier">generate_key!</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">ec</span>.<span class="ruby-identifier">private_key</span> <span class="ruby-comment"># =&gt; #&lt;OpenSSL::BN XXXXXX&gt;</span>
</pre>

                              <div class="method-source-code" id="generate_key-21-source">
            <pre>static VALUE ossl_ec_key_generate_key(VALUE self)
{
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
    rb_raise(ePKeyError, &quot;pkeys are immutable on OpenSSL 3.0&quot;);
#else
    EC_KEY *ec;

    GetEC(self, ec);
    if (EC_KEY_generate_key(ec) != 1)
        ossl_raise(eECError, &quot;EC_KEY_generate_key&quot;);

    return self;
#endif
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="EC.html#method-i-generate_key">generate_key</a>
                            </div>

                          </div>

                  <div id="method-i-group" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          group   &rarr; group
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the <a href="EC/Group.html"><code>EC::Group</code></a> that the key is associated with. Modifying the returned group does not affect <em>key</em>.</p>

                              <div class="method-source-code" id="group-source">
            <pre>static VALUE
ossl_ec_key_get_group(VALUE self)
{
    OSSL_3_const EC_KEY *ec;
    const EC_GROUP *group;

    GetEC(self, ec);
    group = EC_KEY_get0_group(ec);
    if (!group)
        return Qnil;

    return ec_group_new(group);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-group-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          group = group
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the <a href="EC/Group.html"><code>EC::Group</code></a> for the key. The group structure is internally copied so modification to <em>group</em> after assigning to a key has no effect on the key.</p>

                              <div class="method-source-code" id="group-3D-source">
            <pre>static VALUE
ossl_ec_key_set_group(VALUE self, VALUE group_v)
{
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
    rb_raise(ePKeyError, &quot;pkeys are immutable on OpenSSL 3.0&quot;);
#else
    EC_KEY *ec;
    EC_GROUP *group;

    GetEC(self, ec);
    GetECGroup(group_v, group);

    if (EC_KEY_set_group(ec, group) != 1)
        ossl_raise(eECError, &quot;EC_KEY_set_group&quot;);

    return group_v;
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-initialize_copy" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">initialize_copy</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="initialize_copy-source">
            <pre>static VALUE
ossl_ec_key_initialize_copy(VALUE self, VALUE other)
{
    EVP_PKEY *pkey;
    EC_KEY *ec, *ec_new;

    TypedData_Get_Struct(self, EVP_PKEY, &amp;ossl_evp_pkey_type, pkey);
    if (pkey)
        rb_raise(rb_eTypeError, &quot;pkey already initialized&quot;);
    GetEC(other, ec);

    ec_new = EC_KEY_dup(ec);
    if (!ec_new)
        ossl_raise(eECError, &quot;EC_KEY_dup&quot;);

    pkey = EVP_PKEY_new();
    if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec_new) != 1) {
        EC_KEY_free(ec_new);
        ossl_raise(eECError, &quot;EVP_PKEY_assign_EC_KEY&quot;);
    }
    RTYPEDDATA_DATA(self) = pkey;

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-private-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          private? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns whether this <a href="EC.html"><code>EC</code></a> instance has a private key. The private key (<a href="../BN.html"><code>BN</code></a>) can be retrieved with <a href="EC.html#method-i-private_key"><code>EC#private_key</code></a>.</p>

                              <div class="method-source-code" id="private-3F-source">
            <pre>static VALUE ossl_ec_key_is_private(VALUE self)
{
    OSSL_3_const EC_KEY *ec;

    GetEC(self, ec);

    return EC_KEY_get0_private_key(ec) ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="EC.html#method-i-private_key-3F">private_key?</a>
                            </div>

                          </div>

                  <div id="method-i-private_key" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          private_key   &rarr; OpenSSL::BN
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>See the <a href="../../OpenSSL.html"><code>OpenSSL</code></a> documentation for EC_KEY_get0_private_key()</p>

                              <div class="method-source-code" id="private_key-source">
            <pre>static VALUE ossl_ec_key_get_private_key(VALUE self)
{
    OSSL_3_const EC_KEY *ec;
    const BIGNUM *bn;

    GetEC(self, ec);
    if ((bn = EC_KEY_get0_private_key(ec)) == NULL)
        return Qnil;

    return ossl_bn_new(bn);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-private_key-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          private_key = openssl_bn
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>See the <a href="../../OpenSSL.html"><code>OpenSSL</code></a> documentation for EC_KEY_set_private_key()</p>

                              <div class="method-source-code" id="private_key-3D-source">
            <pre>static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
{
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
    rb_raise(ePKeyError, &quot;pkeys are immutable on OpenSSL 3.0&quot;);
#else
    EC_KEY *ec;
    BIGNUM *bn = NULL;

    GetEC(self, ec);
    if (!NIL_P(private_key))
        bn = GetBNPtr(private_key);

    switch (EC_KEY_set_private_key(ec, bn)) {
    case 1:
        break;
    case 0:
        if (bn == NULL)
            break;
        /* fallthrough */
    default:
        ossl_raise(eECError, &quot;EC_KEY_set_private_key&quot;);
    }

    return private_key;
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-private_key-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">private_key?</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns whether this <a href="EC.html"><code>EC</code></a> instance has a private key. The private key (<a href="../BN.html"><code>BN</code></a>) can be retrieved with <a href="EC.html#method-i-private_key"><code>EC#private_key</code></a>.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="EC.html#method-i-private-3F">private?</a>
                            </div>
                          </div>

                  <div id="method-i-public-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns whether this <a href="EC.html"><code>EC</code></a> instance has a public key. The public key (<a href="EC/Point.html"><code>EC::Point</code></a>) can be retrieved with <a href="EC.html#method-i-public_key"><code>EC#public_key</code></a>.</p>

                              <div class="method-source-code" id="public-3F-source">
            <pre>static VALUE ossl_ec_key_is_public(VALUE self)
{
    OSSL_3_const EC_KEY *ec;

    GetEC(self, ec);

    return EC_KEY_get0_public_key(ec) ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="EC.html#method-i-public_key-3F">public_key?</a>
                            </div>

                          </div>

                  <div id="method-i-public_key" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_key   &rarr; OpenSSL::PKey::EC::Point
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>See the <a href="../../OpenSSL.html"><code>OpenSSL</code></a> documentation for EC_KEY_get0_public_key()</p>

                              <div class="method-source-code" id="public_key-source">
            <pre>static VALUE ossl_ec_key_get_public_key(VALUE self)
{
    OSSL_3_const EC_KEY *ec;
    const EC_POINT *point;

    GetEC(self, ec);
    if ((point = EC_KEY_get0_public_key(ec)) == NULL)
        return Qnil;

    return ec_point_new(point, EC_KEY_get0_group(ec));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public_key-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          public_key = ec_point
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>See the <a href="../../OpenSSL.html"><code>OpenSSL</code></a> documentation for EC_KEY_set_public_key()</p>

                              <div class="method-source-code" id="public_key-3D-source">
            <pre>static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key)
{
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
    rb_raise(ePKeyError, &quot;pkeys are immutable on OpenSSL 3.0&quot;);
#else
    EC_KEY *ec;
    EC_POINT *point = NULL;

    GetEC(self, ec);
    if (!NIL_P(public_key))
        GetECPoint(public_key, point);

    switch (EC_KEY_set_public_key(ec, point)) {
    case 1:
        break;
    case 0:
        if (point == NULL)
            break;
        /* fallthrough */
    default:
        ossl_raise(eECError, &quot;EC_KEY_set_public_key&quot;);
    }

    return public_key;
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-public_key-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">public_key?</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns whether this <a href="EC.html"><code>EC</code></a> instance has a public key. The public key (<a href="EC/Point.html"><code>EC::Point</code></a>) can be retrieved with <a href="EC.html#method-i-public_key"><code>EC#public_key</code></a>.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="EC.html#method-i-public-3F">public?</a>
                            </div>
                          </div>

                  <div id="method-i-to_der" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_der   &rarr; String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Serializes a private or public key to a DER-encoding.</p>

<p>See <a href="EC.html#method-i-to_pem"><code>to_pem</code></a> for details.</p>

<p><strong>This method is kept for compatibility.</strong> This should only be used when the SEC 1/RFC 5915 ECPrivateKey format is required.</p>

<p>Consider using <a href="PKey.html#method-i-public_to_der"><code>public_to_der</code></a> or <a href="PKey.html#method-i-private_to_der"><code>private_to_der</code></a> instead.</p>

                              <div class="method-source-code" id="to_der-source">
            <pre>static VALUE
ossl_ec_key_to_der(VALUE self)
{
    OSSL_3_const EC_KEY *ec;

    GetEC(self, ec);
    if (EC_KEY_get0_public_key(ec) == NULL)
        ossl_raise(eECError, &quot;can&#39;t export - no public key set&quot;);
    if (EC_KEY_get0_private_key(ec))
        return ossl_pkey_export_traditional(0, NULL, self, 1);
    else
        return ossl_pkey_export_spki(self, 1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_pem" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_pem([cipher, password]) &rarr; String
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Serializes a private or public key to a PEM-encoding.</p>
<dl class="rdoc-list label-list"><dt>When the key contains public components only
<dd>
<p>Serializes it into an X.509 SubjectPublicKeyInfo. The parameters <em>cipher</em> and <em>password</em> are ignored.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN PUBLIC KEY-----
[...]
-----END PUBLIC KEY-----</pre>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> instead. This serializes the key into an X.509 SubjectPublicKeyInfo regardless of whether it is a public key or a private key.</p>
</dd><dt>When the key contains private components, and no parameters are given
<dd>
<p>Serializes it into a SEC 1/RFC 5915 ECPrivateKey.</p>

<p>A PEM-encoded key will look like:</p>

<pre>-----BEGIN EC PRIVATE KEY-----
[...]
-----END EC PRIVATE KEY-----</pre>
</dd><dt>When the key contains private components, and <em>cipher</em> and <em>password</em> are given
<dd>
<p>Serializes it into a SEC 1/RFC 5915 ECPrivateKey and encrypts it in OpenSSL’s traditional PEM encryption format. <em>cipher</em> must be a cipher name understood by <a href="../Cipher.html#method-c-new"><code>OpenSSL::Cipher.new</code></a> or an instance of <a href="../Cipher.html"><code>OpenSSL::Cipher</code></a>.</p>

<p>An encrypted PEM-encoded key will look like:</p>

<pre>-----BEGIN EC PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,733F5302505B34701FC41F5C0746E4C0

[...]
-----END EC PRIVATE KEY-----</pre>

<p>Note that this format uses MD5 to derive the encryption key, and hence will not be available on FIPS-compliant systems.</p>
</dd></dl>

<p><strong>This method is kept for compatibility.</strong> This should only be used when the SEC 1/RFC 5915 ECPrivateKey format is required.</p>

<p>Consider using <a href="PKey.html#method-i-public_to_pem"><code>public_to_pem</code></a> (X.509 SubjectPublicKeyInfo) or <a href="PKey.html#method-i-private_to_pem"><code>private_to_pem</code></a> (PKCS #8 PrivateKeyInfo or EncryptedPrivateKeyInfo) instead.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="EC.html#method-i-export">export</a>
                            </div>
                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

